<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>实例化BufferGeometry2</title>
  <style>
    body {
      margin: 0;
      overflow: hidden;
    }
    canvas {
      outline: none;
    }
  </style>
</head>
<body>
  <script type="x-shader/x-vertex" id="vertexShader">
    precision highp float;

    attribute vec3 instancePosition;
    attribute vec4 instanceQuaternion;
    attribute vec3 instanceScale;

    varying vec3 vColor;

    vec3 applyTRS(vec3 position, vec3 translation, vec4 quaternion, vec3 scale) {
      position *= scale;
      position += 2.0 * cross(quaternion.xyz, cross(quaternion.xyz, position) + quaternion.w * position);
      return position + translation;
    }

    void main() {
      vColor = color;

      vec3 transformed = applyTRS(position.xyz, instancePosition, instanceQuaternion, instanceScale);

      gl_Position = projectionMatrix * modelViewMatrix * vec4(transformed, 1);
    }
  </script>
  <script type="x-shader/x-fragment" id="fragmentShader">
    precision highp float;

    varying vec3 vColor;

    void main() {
      gl_FragColor = vec4(vColor, 1);
    }
  </script>
  <script src="./_instancing2.js" type="module"></script>
</body>
</html>